package transfer;

import android.database.Cursor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class Cursor2List {
    public static List transferCursor(Cursor cursor) {
        List arrayList = new ArrayList();
        while (cursor.moveToNext()) {

            Map map = new TreeMap();
            String value = "";
            for (int i = 0; i < cursor.getColumnCount(); i++) {

                if (cursor.getType(i) == Cursor.FIELD_TYPE_STRING) {
                    value = cursor.getString(i) + "";

                } else if (cursor.getType(i) == Cursor.FIELD_TYPE_BLOB) {
                    value = cursor.getBlob(i) + "";

                } else if (cursor.getType(i) == Cursor.FIELD_TYPE_INTEGER) {
                    value = cursor.getInt(i) + "";

                } else if (cursor.getType(i) == Cursor.FIELD_TYPE_FLOAT) {
                    value = cursor.getFloat(i) + "";

                } else if (cursor.getType(i) == Cursor.FIELD_TYPE_NULL) {
                    value = null + "";

                }
                String name = cursor.getColumnName(i);

                map.put(name, value);

            }
            arrayList.add(map);
        }
        return arrayList;
    }
}
